'use strict';
const data = {
  list: [{
    id: 1,
    title: 'TypeScript-JavaScript的超集，可以编译成纯JavaScript。',
    summary: 'JavaScript的超集，可以编译成纯JavaScript。',
    hits: 200,
    url: 'https://www.tslang.cn/'
  }, {
    id: 2,
    title: 'TypeORM',
    summary: 'TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7)',
    hits: 550,
    url: 'http://typeorm.io/#/'
  }, {
    id: 3,
    title: 'egg-为企业级框架和应用而生',
    summary: 'Born to buildbetter enterprise frameworks and apps with Node.js & Koa',
    hits: 278,
    url: 'https://eggjs.org/'
  }, {
    id: 4,
    title: 'vue',
    summary: 'Vue.js是一套构建用户界面(user interface)的渐进式框架。与其他重量级框架不同的是，Vue 从根本上采用最小成本、渐进增量(incrementally adoptable)的设计',
    hits: 998,
    url: 'https://vuefe.cn/v2/guide/'
  }, {
    id: 4,
    title: 'ElementUI-一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库',
    summary: 'Element提供了丰富的前端组件库',
    hits: 232,
    url: 'http://element-cn.eleme.io/#/zh-CN'
  }]
};

let id: number = 1;

data.list = data.list.concat(data.list);
data.list = data.list.concat(data.list);

data.list.forEach((item) => {
  item.id = id++;
});

const total = data.list.length;
export function getPage(pageIndex: number = 1, pageSize: number = 10) {
  const start = (pageIndex - 1) * pageSize;
  const end = start + Number(pageSize);
  return { list: data.list.slice(start, end), total };
}

export function getDetail(key: number) {
  return data.list.filter((item) => {
    return item.id === key;
  }).slice(0, 1);
}